<?php

namespace app\index\controller;

use think\facade\Db;
use think\facade\View;

class SolutionController extends BaseController {

    public function index() {
        $solutionList = Db::name('WebSolution')
            ->field('id, title, img_url, `desc`, DATE_FORMAT(create_time, "%Y-%m-%d") as create_time')
            ->order('sort, id desc')->select()->toArray();
        View::assign([
            'solutionList' => $solutionList,
        ]);

        return view();
    }

    public function detail() {
        $id = input('id/d', 0);
        if ($id <= 0) exit('参数错误!');
        $solution = Db::name('WebSolution')->where('id', $id)->field('*, DATE_FORMAT(create_time, "%Y-%m-%d") as create_time')->find();
        // p($solution);

        $solutionList = Db::name('WebSolution')
            ->field('id, title, img_url, `desc`, DATE_FORMAT(create_time, "%Y-%m-%d") as create_time')
            ->order('sort, id desc')->select()->toArray();


        $newsList = Db::name('WebNews')
            ->field('id, title, img_url, `desc`, DATE_FORMAT(create_time, "%Y-%m-%d") as create_time')
            ->order('sort, id desc')->select()->toArray();

        View::assign([
            'solution' => $solution,
            'solutionList' => $solutionList,
            'newsList' => $newsList,
        ]);
        return view();
    }
}
